package com.ouken.tool;



import java.util.ArrayList;

import com.ouken.activity.R;
import com.ouken.activity.R.drawable;

import android.content.Context;
import android.graphics.Color;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class DeleteSSIDListAdapter extends BaseAdapter {
	Context context;  
	ArrayList<Device> contents; 
    ArrayList<String> deleteDeviceLists;
	public DeleteSSIDListAdapter(Context context,ArrayList<Device> contents,  ArrayList<String> deleteDeviceLists) {
		this.context=context;  
        this.contents=contents;
        this.deleteDeviceLists=deleteDeviceLists;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return contents.size();  
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return "ok";  
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;  
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		if(convertView==null){  
            LayoutInflater inflater=LayoutInflater.from(context);  
            convertView=inflater.inflate(R.layout.delete_device_list_item, null);  
        }  
		  ImageView device_logo=(ImageView)convertView.findViewById(R.id.delete_device_list_logo);  
	      TextView device_name=(TextView)convertView.findViewById(R.id.delete_device_list_name);  
	      TextView device_description=(TextView)convertView.findViewById(R.id.delete_device_list_description);  
	      final ImageButton deivce_check = (ImageButton)convertView.findViewById(R.id.delete_device_list_check);  
	           
	      device_logo.setImageResource(contents.get(position).getDeviceLogo());
	      device_name.setText(contents.get(position).getDeviceName());
	      device_description.setText(contents.get(position).getDeviceDescription());
	      
	      if(deleteDeviceLists.contains(contents.get(position).getDeviceSSID())){
	    	  deivce_check.setImageResource(drawable.radio_on);
	      }else{
	    	  deivce_check.setImageResource(drawable.radio_no);
	      }
	      
	      
	      deivce_check.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				if(deleteDeviceLists.contains(contents.get(position).getDeviceSSID())){
			    	  deleteDeviceLists.remove(contents.get(position).getDeviceSSID());
			    	  deivce_check.setImageResource(drawable.radio_no);
			      }else{
			    	  deleteDeviceLists.add(contents.get(position).getDeviceSSID());
			    	  deivce_check.setImageResource(drawable.radio_on);
			      }
			}
		});
	     
       
        return convertView;  
	}

}
